package com.easychat.controller;

import com.easychat.annotation.GlobalInterceptor;
import com.easychat.entity.dto.TokenUserInfoDto;
import com.easychat.entity.enums.ResponseCodeEnum;
import com.easychat.entity.enums.UserStatusEnum;
import com.easychat.entity.po.GroupInfo;
import com.easychat.entity.po.UserInfo;
import com.easychat.entity.query.GroupInfoQuery;
import com.easychat.entity.query.UserInfoQuery;
import com.easychat.entity.vo.PaginationResultVO;
import com.easychat.entity.vo.ResponseVO;
import com.easychat.exception.BusinessException;
import com.easychat.service.GroupInfoService;
import com.easychat.service.UserInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @Author: yudaxian
 * @Description: TODO
 * @DateTime: 2024/8/16 10:28
 **/
@RestController
@RequestMapping("/admin")
public class AdminGroupInfoController extends ABaseController{

    @Resource
    private GroupInfoService groupInfoService;

    @GlobalInterceptor
    @RequestMapping("/loadGroup")
    public ResponseVO loadUser(HttpServletRequest request, @NotEmpty String pageNo) {
//        TokenUserInfoDto tokenUserInfo = getTokenUserInfo(request);
        GroupInfoQuery groupInfoQuery = new GroupInfoQuery();
        groupInfoQuery.setPageNo(Integer.parseInt(pageNo));
        groupInfoQuery.setOrderBy("create_time desc");
        PaginationResultVO<GroupInfo> list = groupInfoService.findListByPage(groupInfoQuery);
        return getSuccessResponseVO(list);
    }

    @GlobalInterceptor
    @RequestMapping("/dissolutionGroup")
    public ResponseVO dissolutionGroup(HttpServletRequest request, @NotEmpty String groupId) {
        TokenUserInfoDto tokenUserInfo = getTokenUserInfo(request);
        GroupInfo groupInfo = groupInfoService.getGroupInfoByGroupId(groupId);
        if (null == groupId) {
            throw new BusinessException(ResponseCodeEnum.CODE_600);
        }
        groupInfoService.dissolutionGroup(groupInfo.getGroupOwnerId(), groupId);
        return getSuccessResponseVO(null);
    }

}
